package com.shell.governor.audit.online.service.impl;

import com.shell.bee.persistence.service.impl.PersistentServiceImpl;
import com.shell.constant.ind.PubConstants;
import com.shell.framework.utils.SysDateUtil;
import com.shell.governor.audit.online.dao.PubOnlineDao;
import com.shell.governor.audit.online.service.PubOnlineService;
import com.shell.governor.audit.po.PubOnline;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("pubOnlineServiceImpl")
public class PubOnlineServiceImpl extends PersistentServiceImpl<PubOnline> implements PubOnlineService {
	@Autowired
	private PubOnlineDao onlineDao;

	public int saveOnlineRecord(String sessionId, String loginName, String loginAddr) {
		PubOnline online = new PubOnline();
		online.setLoginName(loginName);
		online.setLoginAddr(loginAddr);
		List<PubOnline> onlineList = this.onlineDao.select(online);
		if ((onlineList != null) && (onlineList.size() > 0)) {
			for (PubOnline onlineTemp : onlineList) {
				this.onlineDao.delete(onlineTemp);
			}
		}
		online.setOnlineId(sessionId);
		online.setLoginTime(SysDateUtil.getSystemDateTime());
		online.setTrmlCode(PubConstants.TerminalCode.TRML_PC);
		if (this.onlineDao.selectByPrimaryKey(sessionId) != null) {
			return this.onlineDao.updateByPrimaryKey(online);
		}
		return this.onlineDao.insert(online);
	}
}
